﻿using Logistics.Track;
using Microsoft.AspNetCore.Mvc;

namespace Logistics.Web.Controllers
{
    public class CarryTrackController : Controller
    {
        private readonly ICarryTrackAppService _carrytrack;
        public CarryTrackController(ICarryTrackAppService carrytrack)
        {
            _carrytrack = carrytrack;
        }
        public IActionResult Index()
        {
            return View();
        }
        public IActionResult GetList(int page = 1, int limit = 3, string Title = "", string Time = "")
        {
            var carrytrackSearchDto = new CarryTrackSearchDto
            {
                SkipCount = (page - 1) * limit,
                MaxResultCount = limit,
                Sorting = "Id desc",
                Title = Title,
                Time = Time,
            };
            var result = _carrytrack.GetDapperCarryTracks(carrytrackSearchDto).Result;
            var count = result.TotalCount;
            return Ok(new { data = result.Items, count, code = "0", msg = "" });
        }
        public IActionResult TrackLine(int Id = 1)
        {
            ViewBag.Id = Id;
            return View();
        }
        public IActionResult GetLine(int Id = 3)
        {
            var list = _carrytrack.GetLineById(Id).Result;
            return Ok(list);
        }
        public IActionResult Update(int Id,int Conditions)
        {
            string Condition = ""; 
            if (Conditions == 1)
            {
                Condition = "运输中";
            }
            else if (Conditions == 2)
            {
                Condition = "已完成";
            }
            int result = _carrytrack.UpdateCarryTrack(Id, Condition).Result;
            return Ok(result);
        }
    }
}
